echo gettype($var2) . '<hr />'; //array
var_dump($var2); //array(1) { [7]=> int(123) }
<?php
$ary1 = array(1, 2.3, false, 'Brad',5);
echo gettype($ary1);
//array
var_dump($ary1);
//arrayarray(5)
//{ [0]=> int(1) [1]=> float(2.3) [2]=> bool(false) [3]=> string(4)"Brad"
// [4]=> int(5) }
?>
$ary1 = array(1, 2, 3, 4);
echo $ary1[4] . '<hr />'; //錯誤
$ary1 = array(1, 2, 3, 4);
echo count($ary1) . '<hr />';
//key:vaule
$person['name'] = 'Brad';
$person['age'] = 18;
$person['gender'] = true;
$person[1] = 123;
foreach ($person as $key => $value) {
echo "{$key} : {$value}<br />";
}
JS陣列是物件的一種(陣列表現出Array)
PHP陣列,是資料結構,比較像python的dictionary
$p = array(7 => 0, 0, 0, 77 => 0, 0, 0);
var_dump($p);
//array(6) { [7]=> int(0) [8]=> int(0)
//[9]=> int(0) [77]=> int(0) [78]=> int(0) [79]=> int(0) }
$p = array(1 => 0, 0, 0, 0, 0, 0);
//陣列從1開始
for ($i = 0; $i < 1000000; $i++) {
$point = rand(1, 6); //亂數1~6
$p[$point]++; //p內[陣列] 亂數如果1,開[1]裡面+1(++)
http://localhost/Myphp/brad19.php